package cn.scantd.main;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

import com.jfext.configLoader.ConfigLoader;
import com.jfext.configLoader.ConfigUtils;

import cn.scantd.core.ASTBuilder;
import cn.scantd.core.attrs.Scope;
import cn.scantd.kit.FileKit;
import cn.scantd.kit.StrKit;

/**
 * 访问主程序
 * 
 * @author xuq
 * @date 2015年10月5日
 * @version 1.0
 */
public class Main {

	public static void main(String[] args) {
		// config load
		ConfigLoader.load("classpath:config");
		
		// trace files
		List<File> files = new ArrayList<File>();
		String target = ConfigUtils.getStr("scan", "scan.target");
		
		FileKit.traceListFile(files, target, new FileFilter() {
			
			@Override
			public boolean accept(File pathname) {
				if (".java".equals(FileKit.getExtension(pathname))) {
					return true;
				}
				return false;
			}
		});
		
		// generator ast
		String output = ConfigUtils.getStr("scan", "scan.output");
		String rtJar = ConfigUtils.getStr("scan", "scan.java_rt_jar");
		Scope scope = Scope.valueOf(StrKit.trim(ConfigUtils.getStr("scan", "scan.scope")));
		
        String[] sources = new String[]{target};
        String[] classpath = new String[]{rtJar}; 
        String[] encode = new String[]{ConfigUtils.getStr("scan", "scan.encode")};
        
        for (File file : files) {
//            ASTBuilder.build(file, scope, sources, classpath, encode, output, new Callback() {
//				
//				@Override
//				public void go(String targetDic, JavaType javaType) {
//					// do anything you want
//				}
//			});
        	ASTBuilder.build(file, scope, sources, classpath, encode, output, null);
        }
	}
	
}
